package com.example.springdemo7;

import com.aop.AspectConfig;
import com.aop.UserDao;
import com.aop.UserDaoByAno;
import com.bean.AnoConfig;
import com.bean.Customer;
import com.bean.CustomerByAno;
import com.bean.CustomerConstruct;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
public class SpringDemo7Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringDemo7Application.class, args);

        ApplicationContext context = new ClassPathXmlApplicationContext("appConfig.xml");
//        Customer customer = (Customer) context.getBean("cu");
//        System.out.println("装载的bean id=" + customer.getId() + " name=" + customer.getUname() +
//                " password=" + customer.getPassword());
//
//        System.out.println("****************以下是构造器注入*******************");
//        CustomerConstruct cu2 = (CustomerConstruct) context.getBean("cu2");
//        System.out.println("装载的bean id=" + cu2.getId() + " name=" + cu2.getUname() +
//                " password=" + cu2.getPassword());
//
//        System.out.println("*******以下有注解装载bean");
//        ApplicationContext con1 = new AnnotationConfigApplicationContext(AnoConfig.class);
//        CustomerByAno cuAno = con1.getBean(CustomerByAno.class);
//        System.out.println("装载的bean id=" + cuAno.getId() + " name=" + cuAno.getUname() +
//                " password=" + cuAno.getPassword());
        //以下是基于xml方式实现的AspectJ
//        UserDao userDao = (UserDao) context.getBean("userImpl");
//        userDao.addUser();

        //以下是基于注解方式实现的AspectJ
        ApplicationContext con2 = new AnnotationConfigApplicationContext(AspectConfig.class);
        UserDaoByAno userDaoByAno = con2.getBean(UserDaoByAno.class);
        userDaoByAno.addUser();

    }

    @GetMapping("/class7")
    public String sayHello() {
        return "my spring project by class 7";
    }
}
